Creation of Solid Geometry Surface Models for 3D-Printing, Shape Optimization, Topology Optimization (PDE-Toolbox), and Dynamic Simulation (Simscape Multi-Body)

Part A - Polygon Based Contours and Contour Manipulation

Tim Lueth - Professor at Technical Universiity of Munich - Germany - 2019
Set Java Heap to 2048 MByte

1 Introduction and Examples

1.1 Create a Simple Solid Geometry such as a Cylinder in [mm]

SGofCPLcommand('c 4, h 5'); SG=ans; % Create a Cylinder diameterl 4 height 5
SGofCPLcommand('c 4, h 5')

1.2 Write and Read Colored Geometries using STL Files

desktopdir('','user'); % Set the default user dekstop directory
SGwriteSTL(SG,'Cylinder'); % write into STL File
A=SGreadSTL('Cylinder') % read from STL File
LOADING BINARY STL-File: /Users/timlueth/Desktop/Cylinder.STL Binary Header: COLOR=RGBA,MATERIAL=AAAABBBBCCCCDDDD;SOLID "Cylinder by timlueth" 06-Jun-2019 19 Color of solid defined as: "k" Alpha of solid defined as: 65.00 Number of facets: 76 0..
A = struct with fields:
VL: [40×3 double] FL: [76×3 double] col: [82 71 66] alpha: 65 FC: [76×3 double]
A=retainfields(A,'VL','FL'); % remove colors and transparency, retain just geometry
SGfigure; view(-30,30); SGplot(A,'g'); % plot in green

1.3 Create a Complex Mechanisms (Finray Structure by Yilun Sun)

SGofCPLcommand(['cs 18 0 105 -9,dup,move 4.5 0,-,enter,d 1.5 30 -1.8,dupc 5 1 15,r',...
'ot 9 0 0,+,enter,d 1.5 30 1.8,dupc 5 1 15,rot -9 0 0,+,h 10,enter,d 3.48 30 -1.8',...
',d 2.19 30 -1.8,dupc 5 1 15,rot 9 0 0,enter,d 3.48 30 1.8,d 2.19 30 1.8,dupc 5 1',...
' 15,rot -9 0 0,+,h 2,dups 1 1 2 6,+,enter,b 1.6 40,move 29.85 0,dupc 5 1 14.86,e',...
'nter,cs 18 0 110 -9,move 12 0,&,h 5,move 0 0 2.5,+,enter,b 6 50,move 105 0,h 11,',...
'move 0 0 -0.5,cat']);
SGofCPLcommand('cs 18 0 105 -9,dup,move 4.5 0,-,enter,d 1.5 30 -1.8,dupc 5 1 15,rot 9 0 0,+,enter,d 1.5 30 1.8,dupc 5 1 15,rot -9 0 0,+,h 10,enter,d 3.48 30 -1.8,d 2.19 30 -1.8,dupc 5 1 15,rot 9 0 0,enter,d 3.48 30 1.8,d 2.19 30 1.8,dupc 5 1 15,rot -9 0 0,+,h 2,dups 1 1 2 6,+,enter,b 1.6 40,move 29.85 0,dupc 5 1 14.86,enter,cs 18 0 110 -9,move 12 0,&,h 5,move 0 0 2.5,+,enter,b 6 50,move 105 0,h 11,move 0 0 -0.5,cat') SGofCPLcommand(['cs 18 0 105 -9,dup,move 4.5 0,-,enter,d 1.5 30 -1.8,dupc 5 1 15,rot 9 0 0,+,enter,d 1.5 30 1.8,dupc 5 1 15,rot -9 0 0,+,h 10,enter,d 3.48 30 -1.8,d 2.19 30 -1.8,dupc 5 1 15,rot 9 0',... ' 0,enter,d 3.48 30 1.8,d 2.19 30 1.8,dupc 5 1 15,rot -9 0 0,+,h 2,dups 1 1 2 6,+,enter,b 1.6 40,move 29.85 0,dupc 5 1 14.86,enter,cs 18 0 110 -9,move 12 0,&,h 5,move 0 0 2.5,+,enter,b 6 50,move 1',... '05 0,h 11,move 0 0 -0.5,cat'])

1.4 Create a Complex Mechanisms (KinetiX by Yilun Sun)

SGofCPLcommand(['b 5 5,h 4.5,roty 90,move -4.5 0 0,save B,enter,b 3 5,enter,d 5 1.',...
'5 0,+,h 1.5,save A,move 1.5 0 -2.5,dups 1 1 2 2,+,enter,d 2.5 3 0,h 10,move 0 0 ',...
'-5,-,enter,load A,rotz 180,move 4.5 0 -0.75,enter,d 2 3 0,h 5,move 0 0 -2.5,+,+,',...
'enter,load B,move 10.5 -0.01 0,+,move 4.5 0 0,save C,dups 1 7 1 15,enter,load C,',...
'rotz 90,move -2.5 2.5 0,dups 2 1 1 15,dupg 1 3 1 40,+,enter,load C,rotx 45,rotz ',...
'90,move -2.5 22.5 0,enter,load C,rotx -45,rotz 90,move 17.5 22.5 0,+,dupg 1 3 1 ',...
'40,+,enter,sph 8.67,dup,rotx 180,+,move -2.5 0 0,dupg 2 7 1 20,cat']);
SGofCPLcommand('b 5 5,h 4.5,roty 90,move -4.5 0 0,save B,enter,b 3 5,enter,d 5 1.5 0,+,h 1.5,save A,move 1.5 0 -2.5,dups 1 1 2 2,+,enter,d 2.5 3 0,h 10,move 0 0 -5,-,enter,load A,rotz 180,move 4.5 0 -0.75,enter,d 2 3 0,h 5,move 0 0 -2.5,+,+,enter,load B,move 10.5 -0.01 0,+,move 4.5 0 0,save C,dups 1 7 1 15,enter,load C,rotz 90,move -2.5 2.5 0,dups 2 1 1 15,dupg 1 3 1 40,+,enter,load C,rotx 45,rotz 90,move -2.5 22.5 0,enter,load C,rotx -45,rotz 90,move 17.5 22.5 0,+,dupg 1 3 1 40,+,enter,sph 8.67,dup,rotx 180,+,move -2.5 0 0,dupg 2 7 1 20,cat') SGofCPLcommand(['b 5 5,h 4.5,roty 90,move -4.5 0 0,save B,enter,b 3 5,enter,d 5 1.5 0,+,h 1.5,save A,move 1.5 0 -2.5,dups 1 1 2 2,+,enter,d 2.5 3 0,h 10,move 0 0 -5,-,enter,load A,rotz 180,move 4.5',... ' 0 -0.75,enter,d 2 3 0,h 5,move 0 0 -2.5,+,+,enter,load B,move 10.5 -0.01 0,+,move 4.5 0 0,save C,dups 1 7 1 15,enter,load C,rotz 90,move -2.5 2.5 0,dups 2 1 1 15,dupg 1 3 1 40,+,enter,load C,rot',... 'x 45,rotz 90,move -2.5 22.5 0,enter,load C,rotx -45,rotz 90,move 17.5 22.5 0,+,dupg 1 3 1 40,+,enter,sph 8.67,dup,rotx 180,+,move -2.5 0 0,dupg 2 7 1 20,cat'])

1.5 Create a Flexible Hinge Chain (Shaw's Hinge by Yilun Sun)

SGofCPLcommand(['cs 90 3 3.3,move -3.15,dup,rot 180 0 0,+,h 3,move 0 0 -1.5,dup,ro',...
'tx 180,move 0 0 -3.3,dups 1 1 2 3.6,enter,b 8 8,h 6.6,move 0 0 -3.3,&,+,enter,d ',...
'5.4 -3.15 0 40,enter,b 2.7 6.7,move -4.5,+,h 6.7,move 0 0 -3.35,dupr 2,+,dup,dup',...
'g 3 1 1 23.2,swap,rotx 90,dupg 2 1 1 23.2,move 11.6,+']);
SGofCPLcommand('cs 90 3 3.3,move -3.15,dup,rot 180 0 0,+,h 3,move 0 0 -1.5,dup,rotx 180,move 0 0 -3.3,dups 1 1 2 3.6,enter,b 8 8,h 6.6,move 0 0 -3.3,&,+,enter,d 5.4 -3.15 0 40,enter,b 2.7 6.7,move -4.5,+,h 6.7,move 0 0 -3.35,dupr 2,+,dup,dupg 3 1 1 23.2,swap,rotx 90,dupg 2 1 1 23.2,move 11.6,+') SGofCPLcommand(['cs 90 3 3.3,move -3.15,dup,rot 180 0 0,+,h 3,move 0 0 -1.5,dup,rotx 180,move 0 0 -3.3,dups 1 1 2 3.6,enter,b 8 8,h 6.6,move 0 0 -3.3,&,+,enter,d 5.4 -3.15 0 40,enter,b 2.7 6.7,move',... ' -4.5,+,h 6.7,move 0 0 -3.35,dupr 2,+,dup,dupg 3 1 1 23.2,swap,rotx 90,dupg 2 1 1 23.2,move 11.6,+'])

1.6 Help for SGCL

SG=SGofCPLcommand('?');
SGofCPLcommands supports the following commands, separated by commas: See publishable tutorial VLFL_EXP45.m === CPL shape commands ================================= b x-size y-size [d] => Box as rectangle or displace trapaze c diameter diameter edges => Cylinder or ellipse as polygon cs phi r-outer r-inner offset => Cylinder segment with angle co r-outer length r-inner => Cylinder oval segment with optional holes d diameter x-coord y-coord n-faces => Drilling hole at x/y with n edges g diameter teeth-nr turn => Gear that it turned (f.i. 0.5 teeth) ms diameter-1 diameter-2 => Motor shaft contour === CPL manipulation commands ================================= move x-coord y-coord => Move the CPL relatively cp x-coord y-coord => Center point change ch distance radius => Convex hull in distance with optional radius dupc x-copies y copies distance => Duplicates contour in as x y pattern dupr radius number offset => Duplicates contour radial in n copies rad radius => Radial edges (+r) or cuts (-r) at each corner rot degree x y => Rotate a contour ccw by degree on centerpoint x y, default is center of CPL === CPL stack commands ================================= enter => current CPL is shifted to the stack dup => current CPL is duplicated to the stack swap => current CPL is swaped with CPL on stack +/add => current CPL is added to stack CPL -/sub => current CPL is substracted from stack CPL rem => stack CPL ist substracted from current CPL &/isec => current CPL is intersected with stack CPL hs height => stack connection using height === CPL to solid commands ================================= h height z-displacement => Height of the extruded solid hc height z-displacement => Height of extrusion with smoothed edges r angle pitch => Extrusion by rotation (degree) and optional pitch === SG element commands ================================= scr mm length diameter => Screw/Cutter/Nut threat of diameter and length sph diameter end-angle => Sphere === SG manipulation commands ================================= move x-coord y-coord => Move the solid relatively cham rar upper-dist lower-dist => Chamfer the edges of a 2.5 solid rotx degree => rotate around the x-axis roty degree => rotate around the y-axis rotz degree => rotate around the z-axis melt => Boolean addition of all solid elements text string => Add a string to the largest surface dupr number => Duplicates solids radial in n copies dups nx ny nz d => Duplicates solid spatial in x y z with distance d dupg nx ny nz d => Duplicates solid on a grid in x y z with distance d hollow wall => Creates a hollow solid shell wall distance => Creates a shell for the solid cutz z1 z2 => Cuts the solid at z1 and z2 === SG save and restore commands ================================= save name => saves the solid into name.SG load name => loads a solid from name.SG write name => saves the solid into File name.STL read name => reads the solid from File name.STL mag fact => magnifies the current solid col color => colors the faces of the current solid === SG stack commands ================================= enter => current SG is shifted to the stack dup => current SG is duplicated to the stack swap => current SG is swaped with SG on stack clear nr => Clear stack content 1..n +/add => current SG is added to stack SG -/sub => current SG is substracted from stack SG rem => stack SG is substracted from current SG &/isec => current SG is intersected with stack SG rel command parameter => current SG is move relatively to stack === Frame commands ================================= fset name ident rotation feature => attach a frame to the current SG falign Stack-Frame SG-Frame degree => align current SG-frame with stack frame and rotate === Macro commands ================================= $cmd: <string>: => Define macro using $1 $2 $3 $4 as parameters $cmd $1 $2 $3 $4 => Use macro as command with $1 $2 $3 $4 as parameters Try: SGofCPLcommand('g 3 22, h 5, c 5, h 20, roty -90, move 10 10') Try: SGofCPLcommand('$cob: co $1 $2 $3, h $3, fset B 1 0 R1, fset F 2 0 R2:, $cob 10 50 5, dup, falign F B 45')

2 Contour Based Commands

2.1 Creation of Closed Polygon Lists (CPL)

2.1.1 Square, Rectangle and Trapeze

SGofCPLcommand('b 20');
SGofCPLcommand('b 20')
SGofCPLcommand('b 20 10');
SGofCPLcommand('b 20 10')
SGofCPLcommand('b 20 10 5');
SGofCPLcommand('b 20 10 5')

2.2.2 Circles, Ellipses, and Polygons

SGofCPLcommand('c 10');
SGofCPLcommand('c 10')
SGofCPLcommand('c 10 5');
SGofCPLcommand('c 10 5')
SGofCPLcommand('c 10 5 8');
SGofCPLcommand('c 10 5 8')
2.2.4 Circle or Oval segment with Optional Holes
SGofCPLcommand('co 10 50');
SGofCPLcommand('co 10 50')
SGofCPLcommand('co 10 50 5');
SGofCPLcommand('co 10 50 5')
2.2.5 Drilling hole at x/y with n edges
SGofCPLcommand('d 10');
SGofCPLcommand('d 10')
SGofCPLcommand('d 10 20');
SGofCPLcommand('d 10 20')
SGofCPLcommand('d 10 20 -10');
SGofCPLcommand('d 10 20 -10')

2.2.6 Gear Contours

SGofCPLcommand('g 10 21');
SGofCPLcommand('g 10 21')
SGofCPLcommand('g 10 9');
SGofCPLcommand('g 10 9')
SGofCPLcommand('g 10 9,c 2');
SGofCPLcommand('g 10 9,c 2')
SGofCPLcommand('g 10 9,c 2 2 4');
SGofCPLcommand('g 10 9,c 2 2 4')

2.2.7 Motor Shaft Contour

SGofCPLcommand('ms 4 3');
SGofCPLcommand('ms 4 3')
SGofCPLcommand('g 10 21,ms 4 3');
SGofCPLcommand('g 10 21,ms 4 3')

2.2 Manipulation of Closed Contours

2.2.1 Shifting Closed Polygons

SGofCPLcommand('b 10 10, move 7 7, d 10');
SGofCPLcommand('b 10 10, move 7 7, d 10')

2.2.2 Convex Hull of Closed Polygon Lists (CPL)

SGofCPLcommand('g 10 21, ch 0');
SGofCPLcommand('g 10 21, ch 0')
SGofCPLcommand('g 10 21, ch 1');
SGofCPLcommand('g 10 21, ch 1')
SGofCPLcommand('g 10 21, ch -1');
SGofCPLcommand('g 10 21, ch -1')
SGofCPLcommand('g 10 21, move 10 10, g 10 21, ch 1');
SGofCPLcommand('g 10 21, move 10 10, g 10 21, ch 1')

2.2.3 Duplicate CPLS as Cartesian Pattern

SGofCPLcommand('g 10 21, dupc 5 5');
SGofCPLcommand('g 10 21, dupc 5 5')
SGofCPLcommand('g 10 21, dupc 5 5 15');
SGofCPLcommand('g 10 21, dupc 5 5 15')

2.2.4 Duplicate CPLs as Radial Pattern

SGofCPLcommand('g 10 21, dupr 20 4');
SGofCPLcommand('g 10 21, dupr 20 4')
SGofCPLcommand('g 10 21, dupr 20 4 45');
SGofCPLcommand('g 10 21, dupr 20 4 45')

2.2.5 Radial edges (+r) or cuts (-r) at each corner

SGofCPLcommand('b 30 20, rad 5');
SGofCPLcommand('b 30 20, rad 5')
SGofCPLcommand('b 30 20, rad -5');
SGofCPLcommand('b 30 20, rad -5')

2.2.6 Rotation at CPL's Center or Center Point

SGofCPLcommand('co 10 50 5');
SGofCPLcommand('co 10 50 5')
SGofCPLcommand('co 10 50 5,rot 45');
SGofCPLcommand('co 10 50 5,rot 45')
SGofCPLcommand('co 10 50 5,rot 45 0 0');
SGofCPLcommand('co 10 50 5,rot 45 0 0')

2.3 Stack Concept for Closed Polygons (CPL)

2.3.1 Push a Closed Polygon on Stack

SGofCPLcommand('co 10 50 5,enter,g 10 21 '); view(-30,30);
SGofCPLcommand('co 10 50 5,enter,g 10 21')

2.3.2 Duplicate a Closed Polygon on Stack

SGofCPLcommand('co 10 50 5, dup'); view(-30,30);
SGofCPLcommand('co 10 50 5, dup')

2.3.3 Exchange a Closed Polygon with Stack

SGofCPLcommand('co 10 50 5,enter,g 10 21, swap'); view(-30,30);
SGofCPLcommand('co 10 50 5,enter,g 10 21, swap')

2.3.4 Boolean Addition a Closed Polygon to Stack Polygon

SGofCPLcommand('b 10 10, move 7 7, enter, d 10');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, add');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, add')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, +');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, +')

2.3.5 Boolean Subtraction a Closed Polygon to Stack Polygon

SGofCPLcommand('b 10 10, move 7 7, enter, d 10');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, sub');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, sub')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, -');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, -')

2.3.6 Boolean Intersection a Closed Polygon with Stack Polygon

SGofCPLcommand('b 10 10, move 7 7, enter, d 10')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10') ans = []
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, isec');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, isec')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, &');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, &')

2.3.7 Boolean Substracttion of the Stack Polygon from Closed Polygon

SGofCPLcommand('b 10 10, move 7 7, enter, d 10');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10')
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, rem');
SGofCPLcommand('b 10 10, move 7 7, enter, d 10, rem')

2.4 Convert Closed Polygon into Solid Geometries

2.4.1 Create Solid between Closed Polygon and Stack

SGofCPLcommand('c 10 10 6, enter, c 10,');
SGofCPLcommand('c 10 10 6, enter, c 10')
SGofCPLcommand('c 5 5, c 1 1, enter, b 5 5, b 2 2, move 2.5 2.5, hs');
SGofCPLcommand('c 5 5, c 1 1, enter, b 5 5, b 2 2, move 2.5 2.5, hs')

2.4.2 Create Solids by Linear Extrusion along z-Axis

SGofCPLcommand('g 10 21, ms 4 3, h 4');
SGofCPLcommand('g 10 21, ms 4 3, h 4')

2.4.3 Create Solids by linear Extrusion and chamfered edges

SGofCPLcommand('b 10 10, c 4 3, hc 4');
SGofCPLcommand('b 10 10, c 4 3, hc 4')

2.4.4 Create Solids by Radial Extrusion and Pitch

SGofCPLcommand('b 10 10,c 5, r 90');
SGofCPLcommand('b 10 10,c 5, r 90')
SGofCPLcommand('b 10 10,c 5, r 270');
SGofCPLcommand('b 10 10,c 5, r 270')
SGofCPLcommand('c 10 20,b 5 5, r 540 40');
SGofCPLcommand('c 10 20,b 5 5, r 540 40')

2.4.5 Combine Solids by Extrusion and Concatenation

SGofCPLcommand('g 10 21, ms 4 3, h 4, c 5,c 2, h 10');
SGofCPLcommand('g 10 21, ms 4 3, h 4, c 5,c 2, h 10')
SGofCPLcommand(['g 5 21,h 3, c 3, h 3, b 10 8, h 6, move 8 0,b 40 10, d 2 -18 0, d',...
' 2 18 0, h 2, b 30 10, h 20 -1'],80); % Limit the output format to 80 chars/line
SGofCPLcommand('g 5 21,h 3, c 3, h 3, b 10 8, h 6, move 8 0,b 40 10, d 2 -18 0, d 2 18 0, h 2, b 30 10, h 20 -1') SGofCPLcommand(['g 5 21,h 3, c 3, h 3, b 10 8, h 6, move 8 0,b 40 10, d 2 -18 0, d',... ' 2 18 0, h 2, b 30 10, h 20 -1'])